package com.example.poemtest.index.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.example.poemtest.R;
import com.example.poemtest.entity.DynastryPoetryBean;
import com.example.poemtest.entity.PoetryInfoBean;
import com.example.poemtest.index.entity.Poetry;
import com.example.poemtest.utils.Constant;
import com.example.poemtest.utils.FullScreenUtil;

/**
 * 小初高具体诗词点击跳转页面
 */
public class StudyPoetryDetailActivity extends AppCompatActivity {

    private TextView poetryTitle, poetryAuthor, poetryDynasty, poetryContent, poetryYiwen;
    private PoetryInfoBean.PoetryInfo poetry;
    private Button favBtn;
    private ImageButton back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FullScreenUtil.getInstance().fullScreen(this,true);
        setContentView(R.layout.activity_study_poetry_detail);
        //绑定控件对象
        setContentView();
        //接收传递过来的信息（已经能够成功接收）
        Intent intent = getIntent();
        poetry = (PoetryInfoBean.PoetryInfo) intent.getSerializableExtra("poetry");
//        String info = poetry.toString();
//        Log.e("info",info);
        //设置数据源
        setData();
        //点击收藏
//        favBtn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (favBtn.getText().equals("收藏")) {
//                    Constant.favPoetry.add(poetry);
//                    favBtn.setText("取消收藏");
//                } else {
//                    for (Poetry p : Constant.favPoetry) {
//                        if (p.getPoetry_content().equals(poetry.getPoetry_content())) {
//                            Constant.favPoetry.remove(p);
//                            favBtn.setText("收藏");}
//                    }
//                }
//            }
//        });
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    /**
     * 设置数据源
     */
    private void setData() {
        for (DynastryPoetryBean.DynastyPoetry p : Constant.favPoetry) {
            if (p.getContent().equals(poetry.getPoetryContent())) {
                favBtn.setText("取消收藏");
                Log.e("包含",p.getContent().equals(poetry.getPoetryContent())+"");
            }
        }
        poetryTitle.setText(poetry.getPoetryTitle());
        poetryAuthor.setText(poetry.getPoetryAuthor());
        poetryDynasty.setText("【"+poetry.getPoetryDynasty()+"】");
        poetryContent.setText(poetry.getPoetryContent());
        poetryYiwen.setText(poetry.getPoetryTranslation());
//        Log.e("传递的译文",poetry.getPoetry_desc().toString());
    }

    /**
     * 绑定控件对象
     */
    private void setContentView() {
        back = findViewById(R.id.back);
        favBtn = findViewById(R.id.fav_btn);
        poetryTitle = findViewById(R.id.poetry_title);
        poetryAuthor = findViewById(R.id.poetry_author);
        poetryDynasty = findViewById(R.id.poetry_dynasty);
        poetryContent = findViewById(R.id.poetry_content);
        poetryYiwen = findViewById(R.id.poetry_yiwen);
    }
}